package com.kw.drug.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kw.drug.common.ResultMapUtil;
import com.kw.drug.entity.Problem;
import com.kw.drug.entity.Returngoods;
import com.kw.drug.service.ReturngoodsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/returngoods")
public class returngoodsController {
    @Autowired
    ReturngoodsService returngoodsService;

    /**
     * 去到退货页面
     */


    @RequestMapping()
    public String returngoodsIndex() {
        return "returngoods";
    }

    /**
     * 分页查询退货列表
     */
    @RequestMapping("/returngoodsQueryPage")
    @ResponseBody
    public Map returngoodsQueryPage(String param, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        try {
            IPage<Returngoods> ipage = returngoodsService.problemQueryPage(param, pageSize, pageNum);
            return ResultMapUtil.getHashMapMysqlPage(ipage);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 进入编辑页面
     */
    @RequestMapping("/returngoodsQueryById")
    public String editIndex(Integer id, Model model) {
        Returngoods returngoods = returngoodsService.selectreturngoodById(id);
        model.addAttribute("obj", returngoods);
        return "returngoodsPage";
    }

    /**
     * 删除记录
     */
    @RequestMapping("/returngoodsDelById")
    @ResponseBody
    public Map returngoodsDelById(Integer id) {
        try {
            Integer integer = returngoodsService.returngoodsDelById(id);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }

    }

    /**
     * 修改记录
     */
    @RequestMapping("/returngoodsEdit")
    @ResponseBody
    public Map update(Returngoods returngoods) {
        try {
            Integer integer = returngoodsService.returngoodsEdit(returngoods);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 跳到新增页面
     */
    @RequestMapping("/returngoodsPage")
    public String returngoodsPage() {
        return "returngoodsPage";
    }

    /**
     * 新增
     */
    @RequestMapping("/returngoodsAdd")
    @ResponseBody
    public Map returngoodsAdd(Returngoods returngoods) {
        try {
            Integer integer = returngoodsService.addReturnGoods(returngoods);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }
}


